home *** CD-ROM | disk | FTP | other *** search
- /*
-
- --------------------------------------------------------------------
- Internet Personal MSAM Sample Setup Template Code
- 1.0b9 version
-
- Steve Falkenburg
- MacDTS 7/22/93
- AppleLink DEVSUPPORT for questions (if you're a supported seed site)
- --------------------------------------------------------------------
-
- *********** WARNING ***************
-
- DO NOT USE MPW C 3.3 TO COMPILE THIS TEMPLATE. IT HAS A BUG WHICH CAUSES
- STRING LITERALS CONTAINING \0 TO NOT COMPILE PROPERLY. INSTEAD, YOU SHOULD
- USE MPW C 3.2.4, WHICH DOESN'T HAVE THIS BUG.
-
- *********** WARNING ***************
- */
-
- #include <Types.h>
- #include <Memory.h>
- #include <Dialogs.h>
- #include <Resources.h>
- #include <String.h>
- #include <Strings.h>
-
- #include <OCE.h>
- #include <OCEAuthDir.h>
- #include <OCEMail.h>
- #include <OCETemplates.h>
- #include <OCEErrors.h>
-
- #include "InternetMailService.code.h"
- #include "InternetProperties.h"
-
- //---------------------------------------------------------------------------------------
-
- pascal OSErr MailServiceCode(DETCallBlockPtr callBlockPtr)
- {
- OSErr err;
-
- // handle the callback if we've got our data or if it's the initial call
-
- if (((callBlockPtr->protoCall.target.selector==kDETSelf) && ((callBlockPtr->protoCall.instancePrivate!=nil) ||
- (callBlockPtr->protoCall.reqFunction == kDETcmdInstanceInit))) ||
- (callBlockPtr->protoCall.reqFunction == kDETcmdInit)) {
-
- // handle the different callbacks
-
- switch (callBlockPtr->protoCall.reqFunction) {
- case kDETcmdInit:
- err = InitTemplate(callBlockPtr);
- break;
- case kDETcmdInstanceInit: // Template instance initialization
- err = InitInstance(callBlockPtr);
- break;
- case kDETcmdInstanceExit: // Template exit- dispose memory
- err = ExitInstance(callBlockPtr);
- break;
- case kDETcmdValidateSave: // about to save an info-page
- err = ValidateSave(callBlockPtr);
- break;
- case kDETcmdPropertyCommand: // property command (item hit)
- err = PropertyItemHit(callBlockPtr);
- break;
- default:
- err = kDETDidNotHandle;
- break;
- }
- }
- else err = kDETDidNotHandle;
-
- if (err<noErr)
- DoError(err);
-
- return err;
- }
-
- //---------------------------------------------------------------------------------------
-
- OSErr InitTemplate(DETCallBlockPtr callBlockPtr)
- {
- DETCallBackBlock callBack;
- OSErr err;
-
- TraceExecution("\pInitTemplate");
-
- callBack.changeCallFors.reqFunction = kDETcmdChangeCallFors;
- callBack.changeCallFors.target.selector = kDETSelf;
- callBack.changeCallFors.newCallFors = callBlockPtr->init.newCallFors | kDETCallForValidation;
- err = CallBackDET(callBlockPtr, &callBack);
-
- return err;
- }
-
-
- OSErr InitInstance(DETCallBlockPtr callBlockPtr)
- {
- GlobalData *globalData;
- DETCallBackBlock callBack;
- OSErr err;
- PackedRecordID assocDir;
- RecordID assocDirUnpacked;
- CreationID attrCID;
-
- TraceExecution("\pInitInstance");
-
- err = CheckFileIDs(callBlockPtr);
- if (err!=noErr)
- return err;
-
- if (callBlockPtr->protoCall.instancePrivate)
- return kInternalError;
-
- globalData = (GlobalData *)NewPtr(sizeof(GlobalData));
- if (MemError()!=noErr)
- return MemError();
-
- callBlockPtr->protoCall.instancePrivate = globalData;
-
- // get our DSSpec and CID and OCESetup dsRefNum
-
- callBack.getDSSpec.reqFunction = kDETcmdGetDSSpec;
- callBack.getDSSpec.target.selector = kDETSelf;
- err = CallBackDET(callBlockPtr, &callBack);
- if (err!=noErr)
- return err;
- globalData->oceSetupDSRef = callBack.getDSSpec.refNum;
- HLock((Handle)callBack.getDSSpec.dsSpec);
- GetCreationIDFromDSSpec(*callBack.getDSSpec.dsSpec,&globalData->mailCID);
- DisposHandle((Handle)callBack.getDSSpec.dsSpec);
-
- // get directoryCID
-
- err = GetSingleValueAttribute(&globalData->mailCID,globalData->oceSetupDSRef,
- OCEGetIndAttributeType(kAssoDirectoryAttrTypeNum),&assocDir,sizeof(PackedRecordID),&attrCID);
- if (err!=noErr)
- return err;
- OCEUnpackRecordID(&assocDir,&assocDirUnpacked);
- OCECopyCreationID(&assocDirUnpacked.local.cid,&globalData->directoryCID);
-
- // read data out of slot,directory records
-
- err = GetMailSlotInfo(globalData->oceSetupDSRef,&globalData->mailCID,
- &globalData->config,&globalData->hasBeenCreated);
- if (err!=noErr)
- return err;
-
- err = GetDirectoryInfo(globalData->oceSetupDSRef,&globalData->directoryCID,
- &globalData->config,&globalData->fakeDirectory);
- if (err!=noErr)
- return err;
-
- // store data into info page if we're modifying an existing record
-
- if (globalData->hasBeenCreated) {
- err = SetInfoPageInformation(callBlockPtr,&globalData->config);
- if (err!=noErr)
- return err;
- err = UpdateDisplayNames(callBlockPtr,globalData);
- if (err!=noErr)
- return err;
- }
-
- return err;
- }
-
-
- OSErr ExitInstance(DETCallBlockPtr callBlockPtr)
- {
- GlobalData *globalData;
-
- TraceExecution("\pExitInstance");
-
- globalData = (GlobalData *)callBlockPtr->protoCall.instancePrivate;
- if (globalData==0L)
- return kInternalError;
-
- DisposPtr((Ptr)globalData);
- if (MemError()!=noErr)
- return MemError();
-
- callBlockPtr->protoCall.instancePrivate = 0;
-
- return noErr;
- }
-
-
- //---------------------------------------------------------------------------------------
-
-
- OSErr ValidateSave(DETCallBlockPtr callBlockPtr)
- {
- GlobalData *globalData;
- OSErr err;
-
- TraceExecution("\pValidateSave");
-
- // read the information out of the info page (we need this to do the exitinstance anyway...
-
- globalData = (GlobalData *)callBlockPtr->protoCall.instancePrivate;
- if (globalData==0L)
- return kInternalError;
-
- if (HasBeenChanged(callBlockPtr,&globalData->config)) {
-
- err = GetInfoPageInformation(callBlockPtr,&globalData->config);
- if (err!=noErr)
- return err;
-
- if (globalData->hasBeenCreated)
- err = ModifyOurSlot(callBlockPtr,globalData);
- else {
- err = CreateOurSlot(callBlockPtr,globalData);
- if (err==noErr)
- globalData->hasBeenCreated = true;
- }
- err = UpdateDisplayNames(callBlockPtr,globalData);
- }
-
- return err;
- }
-
-
- //---------------------------------------------------------------------------------------
-
-
- OSErr PropertyItemHit(DETCallBlockPtr callBlockPtr)
- {
- GlobalData *globalData;
- OSErr err;
-
- TraceExecution("\pPropertyItemHit");
-
- globalData = (GlobalData *)callBlockPtr->protoCall.instancePrivate;
- if (globalData==0L)
- return kInternalError;
-
- switch (callBlockPtr->propertyCommand.property) {
- case kPrSetPassword:
- err = SetUserPassword(globalData->config.dirIdentity.password);
- if (err==noErr)
- DirtyProperty(callBlockPtr, kPrSetPassword);
- break;
- default:
- err = kInternalError;
- break;
- }
-
- return err;
- }
-
-
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
-
-
- OSErr CheckFileIDs(DETCallBlockPtr callBlockPtr)
- {
- OSErr err;
- CreationID msamCID,attrCID;
- long fileID,oldFileID;
- DirGetOCESetupRefNumPB pBlock;
- short dsRefNum;
-
- TraceExecution("\pCheckFileIDs");
-
- // see if the MSAM record exists
-
- pBlock.identity = kIdentity;
- err = DirGetOCESetupRefNum((DirParamBlockPtr)&pBlock,false);
- if (err!=noErr)
- return err;
- dsRefNum = pBlock.dsRefNum;
-
- err = GetSingleRecord(dsRefNum,OCEGetIndRecordType(kMSAMRecTypeNum),kMSAMRecordName,&msamCID);
- if (err==noErr) {
-
- // make sure that the file ID attribute is still valid. If not, replace it, since the user may have upgraded
- // from an older version of the MSAM.
-
- err = GetFileID(callBlockPtr,&fileID);
- if (err!=noErr)
- return err;
- GetSingleValueAttribute(&msamCID,dsRefNum,OCEGetIndAttributeType(kGatewayFileIDAttrTypeNum),
- &oldFileID,sizeof(long),&attrCID);
- if (err!=noErr)
- return err;
- if (oldFileID!=fileID) {
- TraceExecution("\pUpdateFileID");
- err = ChangeSingleAttribute(&msamCID,dsRefNum,OCEGetIndAttributeType(kGatewayFileIDAttrTypeNum),
- &fileID,sizeof(long),typeBinary);
- if (err!=noErr)
- return err;
- }
- }
- else err = noErr;
-
- return err;
- }
-
-
- OSErr GetMailSlotInfo(short dsRef,const CreationID *mailCID,ConfigInformation *config,Boolean *hasBeenCreated)
- {
- PackedRecordID parentMSAM;
- CreationID attrCID;
- OSErr err;
-
- // check for parentmsam attribute, and set has been created flag
-
- err = GetSingleValueAttribute(mailCID,dsRef,OCEGetIndAttributeType(kParentMSAMAttrTypeNum),&parentMSAM,
- sizeof(PackedRecordID),&attrCID);
- if (err==noErr)
- *hasBeenCreated = true;
- else
- *hasBeenCreated = false;
- err = noErr;
-
- if (*hasBeenCreated) {
- // read standard slot info (don't check errors, since it may not exist yet...
-
- err = GetSingleValueAttribute(mailCID,dsRef,OCEGetIndAttributeType(kStdSlotInfoAttrTypeNum),
- &config->stdInfo,sizeof(MailStandardSlotInfoAttribute),&attrCID);
- if (err!=noErr)
- return err;
-
- // read specific slot info
-
- GetSingleValueAttribute(mailCID,dsRef,kSetupAttr,&config->specInfo,sizeof(SpecificSlotInfo),&attrCID);
- if (err!=noErr)
- return err;
- }
- else {
- config->stdInfo.version = kStdSlotInfoVersion;
- config->stdInfo.active = 0xff; // change for b3: make all "i'm at" locations active
- config->stdInfo.sendReceiveTimer.sendTimeKind = kMailTimerFrequency;
- config->stdInfo.sendReceiveTimer.receiveTimeKind = kMailTimerFrequency;
- err = noErr;
- }
-
- return err;
- }
-
-
- OSErr GetDirectoryInfo(short dsRef,const CreationID *directoryCID,ConfigInformation *config,Boolean *directoryIsFake)
- {
- OSErr err;
- OCESetupGetDirectoryInfoPB authBlock;
- CreationID attrCID;
- DirDiscriminator discriminator = {kDirectoryOSType,0};
- PackedRLI pRLI;
- RecordID identRID;
- RString ridName,ridType;
- RString rsNativeName,rsPassword;
- long fake;
-
- // set flag indicating if directory is fake
-
- err = GetSingleValueAttribute(directoryCID,dsRef,OCEGetIndAttributeType(kFakeAttrTypeNum),&fake,sizeof(long),&attrCID);
- if (err==noErr) {
- *directoryIsFake = true;
- }
- else {
- *directoryIsFake = false;
- }
-
- // read ocesetupdirectoryinfo
-
- rsNativeName.charSet = smRoman;
- rsNativeName.dataLength = kRStringMaxChars;
- rsPassword.charSet = smRoman;
- rsPassword.dataLength = kRStringMaxChars;
- ridName.charSet = smRoman;
- ridName.dataLength = kRStringMaxChars;
- ridType.charSet = smRoman;
- ridType.dataLength = kRStringMaxChars;
- pRLI.dataLength = 0;
- identRID.rli = &pRLI;
- OCESetCreationIDtoNull(&identRID.local.cid);
- identRID.local.recordName = &ridName;
- identRID.local.recordType = &ridType;
-
- authBlock.directoryName = kDirectoryName;
- authBlock.discriminator = discriminator;
- authBlock.recordID = &identRID;
- authBlock.nativeName = &rsNativeName;
- authBlock.password = &rsPassword;
- err = OCESetupGetDirectoryInfo((AuthParamBlockPtr)&authBlock,false);
-
- if (err==noErr) {
- strcpy(config->dirIdentity.userName,p2cstr(OCERToPString(&ridName)));
- strcpy(config->dirIdentity.password,p2cstr(OCERToPString(&rsPassword)));
- }
- else {
- // if we don't have an identity yet, zero out name,password
- config->dirIdentity.userName[0] = 0;
- config->dirIdentity.password[0] = 0;
- }
-
- // setup oldpassword field for changes
-
- strcpy(config->dirIdentity.oldPassword,config->dirIdentity.password);
-
- return noErr; // even if the getdirectory info call failed, we should continue
- }
-
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
-
-
- // store information from config information into info page properties
-
- OSErr SetInfoPageInformation(DETCallBlockPtr callBlockPtr,ConfigInformation *config)
- {
- RString rstr;
- OSErr err;
-
- // login name
- OCECToRString(config->dirIdentity.userName, smRoman, &rstr, kRStringMaxChars);
- err = SetStringProperty(callBlockPtr, &rstr, kPrLoginName);
- if (err!=noErr)
- return err;
-
- // password
- // handled directly
-
- // pop server
- OCECToRString(config->specInfo.popServer, smRoman, &rstr, kRStringMaxChars);
- err = SetStringProperty(callBlockPtr, &rstr, kPrPopServer);
- if (err!=noErr)
- return err;
-
- // smtp server
- OCECToRString(config->specInfo.smtpServer, smRoman, &rstr, kRStringMaxChars);
- err = SetStringProperty(callBlockPtr, &rstr, kPrSMTPServer);
- if (err!=noErr)
- return err;
-
- // sendtime
- err = SetNumProperty(callBlockPtr, kPrSendTime, config->stdInfo.sendReceiveTimer.send.frequency);
- if (err!=noErr)
- return err;
-
- // recvtime
- err = SetNumProperty(callBlockPtr, kPrRecvTime, config->stdInfo.sendReceiveTimer.receive.frequency);
- if (err!=noErr)
- return err;
-
- return err;
- }
-
-
- // read information out of info page and store it in config information
-
- OSErr GetInfoPageInformation(DETCallBlockPtr callBlockPtr,ConfigInformation *config)
- {
- RString rstr;
- OSErr err;
-
- // login name
- err = GetStringProperty(callBlockPtr, kPrLoginName, &rstr);
- if (err!=noErr)
- return err;
- strcpy(config->dirIdentity.userName,p2cstr(OCERToPString(&rstr)));
-
- // password
- // handled directly
-
- // pop server
- err = GetStringProperty(callBlockPtr, kPrPopServer, &rstr);
- if (err!=noErr)
- return err;
- strcpy(config->specInfo.popServer,p2cstr(OCERToPString(&rstr)));
-
- // smtp server
- err = GetStringProperty(callBlockPtr, kPrSMTPServer, &rstr);
- if (err!=noErr)
- return err;
- strcpy(config->specInfo.smtpServer,p2cstr(OCERToPString(&rstr)));
-
- // sendtime
- err = GetNumProperty(callBlockPtr, kPrSendTime, &config->stdInfo.sendReceiveTimer.send.frequency);
- if (err!=noErr)
- return err;
-
- // recvtime
- err = GetNumProperty(callBlockPtr, kPrRecvTime, &config->stdInfo.sendReceiveTimer.receive.frequency);
- if (err!=noErr)
- return err;
-
- return err;
- }
-
-
- Boolean HasBeenChanged(DETCallBlockPtr callBlockPtr,ConfigInformation *config)
- {
- ConfigInformation newConfig;
- OSErr err;
-
- // get new config info
-
- err = GetInfoPageInformation(callBlockPtr,&newConfig);
- if (err!=noErr)
- return true; // return changed to catch error later
-
- // check std slot information
-
- if (newConfig.stdInfo.sendReceiveTimer.send.frequency != config->stdInfo.sendReceiveTimer.send.frequency)
- return true;
- if (newConfig.stdInfo.sendReceiveTimer.receive.frequency != config->stdInfo.sendReceiveTimer.receive.frequency)
- return true;
-
- // check specific slot information
-
- if (strcmp(newConfig.specInfo.popServer,config->specInfo.popServer)!=0)
- return true;
- if (strcmp(newConfig.specInfo.smtpServer,config->specInfo.smtpServer)!=0)
- return true;
-
- // check identity
-
- if (strcmp(newConfig.dirIdentity.userName,config->dirIdentity.userName)!=0)
- return true;
- if (strcmp(config->dirIdentity.oldPassword,config->dirIdentity.password)!=0)
- return true;
-
- return false;
- }
-
-
- OSErr UpdateDisplayNames(DETCallBlockPtr callBlockPtr,GlobalData *globalData)
- {
- OSErr err;
- RString rstr;
-
- // rename mailservice record to pop server
-
- OCECToRString(globalData->config.specInfo.popServer, smRoman, &rstr, kRStringMaxChars);
- err = SetRecNameAndType(&globalData->mailCID,globalData->oceSetupDSRef,&rstr,kMailServiceType);
- if (err!=noErr)
- return err;
-
- // set aspect name property to pop server
-
- OCECToRString(globalData->config.specInfo.popServer, smRoman, &rstr, kRStringMaxChars);
- err = SetStringProperty(callBlockPtr, &rstr, kDETAspectName);
- if (err!=noErr)
- return err;
-
- // set aspect user name property to account name
-
- OCECToRString(globalData->config.dirIdentity.userName, smRoman, &rstr, kRStringMaxChars);
- err = SetStringProperty(callBlockPtr, &rstr, kSAMAspectUserName);
- if (err!=noErr)
- return err;
-
- err = RequestSync(callBlockPtr);
- return err;
- }
-
-
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
-
-
- // GetStringProperty
- //
- // gets a string property from the DE template and returns it to us as an RString
- //
- OSErr GetStringProperty(DETCallBlockPtr callBlockPtr, short property, RString *str)
- {
- OSErr err;
- DETCallBackBlock callBack;
-
- callBack.getPropertyRString.reqFunction = kDETcmdGetPropertyRString;
- callBack.getPropertyRString.property = property;
- callBack.getPropertyRString.target.selector = kDETSelf;
- err = CallBackDET(callBlockPtr, &callBack);
-
- if (err==noErr) {
- BlockMove((Ptr)*(callBack.getPropertyRString.propertyValue), (Ptr)str,
- (**(callBack.getPropertyRString.propertyValue)).dataLength+sizeof(ProtoRString));
- DisposHandle((Handle)callBack.getPropertyRString.propertyValue);
- }
-
- return err;
- }
-
-
- // SetStringProperty
- //
- // sets a DET string property to a value that we pass it
- //
- OSErr SetStringProperty(DETCallBlockPtr callBlockPtr, RString *string, short property)
- {
- OSErr err;
- DETCallBackBlock callBack;
-
- callBack.setPropertyRString.reqFunction = kDETcmdSetPropertyRString;
- callBack.setPropertyRString.property = property;
- callBack.setPropertyRString.target.selector = kDETSelf;
- callBack.setPropertyRString.newValue = string;
- err = CallBackDET(callBlockPtr, &callBack);
-
- if (err==noErr)
- err = DirtyProperty(callBlockPtr, property);
-
- return err;
- }
-
-
- // SetNumProperty
- //
- // sets a DET number property to a value that we pass it
- //
- OSErr SetNumProperty(DETCallBlockPtr callBlockPtr, short property, long value)
- {
- OSErr err;
- DETCallBackBlock callBack;
-
- callBack.setPropertyNumber.reqFunction = kDETcmdSetPropertyNumber;
- callBack.setPropertyNumber.property = property;
- callBack.setPropertyNumber.target.selector = kDETSelf;
- callBack.setPropertyNumber.newValue = value;
- err = CallBackDET(callBlockPtr, &callBack);
-
- if (err==noErr)
- err = DirtyProperty(callBlockPtr, property);
-
- return err;
- }
-
-
- // GetNumProperty
- //
- // gets a number property value out of a template and returns it to us
- //
- OSErr GetNumProperty(DETCallBlockPtr callBlockPtr, short property, long *value)
- {
- OSErr err;
- DETCallBackBlock callBack;
-
- callBack.getPropertyNumber.reqFunction = kDETcmdGetPropertyNumber;
- callBack.getPropertyNumber.property = property;
- callBack.getPropertyNumber.target.selector = kDETSelf;
- err = CallBackDET(callBlockPtr, &callBack);
-
- *value = callBack.getPropertyNumber.propertyValue;
-
- return err;
- }
-
-
- // DirtyProperty
- //
- // tells the DE that we've changed a property and that it should mark it for update
- //
- OSErr DirtyProperty(DETCallBlockPtr callBlockPtr, short property)
- {
- OSErr err;
- DETCallBackBlock callBack;
-
- callBack.dirtyProperty.reqFunction = kDETcmdDirtyProperty;
- callBack.dirtyProperty.property = property;
- callBack.dirtyProperty.target.selector = kDETSelf;
-
- err = CallBackDET(callBlockPtr, &callBack);
-
- return err;
- }
-
-
- // GetFileID
- //
- // uses the DE callback mechanism to get the FSSpec for the template file and
- // then changes this value into a file id via PBCreateFileIDRef
- //
- OSErr GetFileID(DETCallBlockPtr callBlockPtr,long *fileID)
- {
- DETCallBackBlock callBack;
- OSErr err;
- FIDParam fidBlock;
-
- callBack.getTemplateFSSpec.reqFunction = kDETcmdGetTemplateFSSpec;
- callBack.getTemplateFSSpec.target.selector = kDETSelf;
- err = CallBackDET(callBlockPtr, &callBack);
- if (err==noErr) {
- fidBlock.ioVRefNum = callBack.getTemplateFSSpec.fsSpec.vRefNum;
- fidBlock.ioSrcDirID = callBack.getTemplateFSSpec.fsSpec.parID;
- fidBlock.ioNamePtr = callBack.getTemplateFSSpec.fsSpec.name;
- err = PBCreateFileIDRef((HParmBlkPtr)&fidBlock,false);
- *fileID = fidBlock.ioFileID;
- if (err==fidExists)
- err = noErr;
- }
-
- return err;
- }
-
-
- // DoBusy
- //
- // tells DE that we want to give some time to other applications for a short while
- // (probably will call WaitNextEvent for us
- //
- OSErr DoBusy(DETCallBlockPtr callBlockPtr)
- {
- DETCallBackBlock callBack;
-
- callBack.busy.reqFunction = kDETcmdBusy;
- return (CallBackDET(callBlockPtr, &callBack));
- }
-
-
- // RequestSync
- //
- // tells the DE that it should make sure all of the DE Templates are in sync with their values
- //
- OSErr RequestSync(DETCallBlockPtr callBlockPtr)
- {
- DETCallBackBlock callBack;
-
- callBack.requestSync.reqFunction = kDETcmdRequestSync;
- callBack.requestSync.target.selector = kDETSelf;
- return CallBackDET(callBlockPtr, &callBack);
- }
-
-
-
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
-
-
- OSErr ModifyOurSlot(DETCallBlockPtr callBlockPtr,GlobalData *globalData)
- {
- OSErr err;
- CreationID msamCID;
- MailModifyMailSlotPB modifySlot;
-
- // get reference to MSAM record
-
- err = GetSingleRecord(globalData->oceSetupDSRef,OCEGetIndRecordType(kMSAMRecTypeNum),kMSAMRecordName,&msamCID);
- if (err!=noErr)
- return err;
-
- // change user's external identity in directory record
-
- err = ChangeDirectoryIdentity(&globalData->directoryCID,globalData->config.dirIdentity.userName,
- globalData->config.dirIdentity.password,globalData->config.dirIdentity.oldPassword);
- if (err!=noErr)
- return err;
- strcpy(globalData->config.dirIdentity.oldPassword,globalData->config.dirIdentity.password);
-
- // change StdSlotInfo attribute in mailservice record
-
- err = ChangeSingleAttribute(&globalData->mailCID,globalData->oceSetupDSRef,OCEGetIndAttributeType(kStdSlotInfoAttrTypeNum),
- &globalData->config.stdInfo,sizeof(MailStandardSlotInfoAttribute),typeBinary);
- if (err!=noErr)
- return err;
-
- // add SpecificSlotInfo to mailservice record
-
- err = ChangeSingleAttribute(&globalData->mailCID,globalData->oceSetupDSRef,kSetupAttr,
- &globalData->config.specInfo,sizeof(SpecificSlotInfo),typeBinary);
- if (err!=noErr)
- return err;
-
- // call MailModifySlot
-
- modifySlot.mailboxRef = 0;
- modifySlot.timeout = kTimeout;
- OCECopyCreationID(&msamCID,&modifySlot.pmsamCID);
- modifySlot.smca.smcaLength = sizeof(SMCA);
- modifySlot.smca.result = 1; // call is running
- modifySlot.smca.userBytes = 0;
- modifySlot.ioCompletion = nil;
- OCECopyCreationID(&globalData->mailCID,&modifySlot.smca.u.slotCID);
-
- err = MailModifyMailSlot((MSAMParam *)&modifySlot);
- if (err!=noErr)
- return err;
-
- // wait for MailModifyMailSlot to complete
-
- while (modifySlot.ioResult==1) {
- err = DoBusy(callBlockPtr);
- if (err!=noErr)
- return err;
- }
-
- err = RequestSync(callBlockPtr);
- if (err!=noErr)
- return err;
-
- return noErr;
- }
-
-
- OSErr CreateOurSlot(DETCallBlockPtr callBlockPtr,GlobalData *globalData)
- {
- OSErr err;
- RString rstr;
- CreationID msamCID,ocesCID,attrCID;
- long version;
- long fileID,oldFileID;
- RecordID msRecordUnpacked;
- PackedRecordID msRecord;
- MailCreateMailSlotPB createMailSlot;
- DirDiscriminator discriminator = {kDirectoryOSType,0};
- RecordID dirRecordUnpacked;
- PackedRecordID dirRecord;
-
- // if directory is fake, check to see if we need to add the native name,etc...
-
- if (globalData->fakeDirectory) {
-
- err = GetSingleValueAttribute(&globalData->directoryCID,globalData->oceSetupDSRef,
- OCEGetIndAttributeType(kDirNativeNameAttrTypeNum),&rstr,sizeof(RString),&attrCID);
- if (err!=noErr) { // native name attribute not present yet
-
- // add native name
-
- OCECToRString(globalData->config.dirIdentity.userName,smRoman,&rstr,kRStringMaxChars);
- err = AddAttribute(&globalData->directoryCID,globalData->oceSetupDSRef,
- OCEGetIndAttributeType(kDirNativeNameAttrTypeNum),&rstr,rstr.dataLength+4,typeRString);
- if (err!=noErr)
- return err;
-
- // add comment
-
- err = AddAttribute(&globalData->directoryCID,globalData->oceSetupDSRef,
- OCEGetIndAttributeType(kCommentAttrTypeNum),kDirectoryComment,kCommentLength,typeRString);
- if (err!=noErr)
- return err;
-
- // add real name
-
- err = AddAttribute(&globalData->directoryCID,globalData->oceSetupDSRef,
- OCEGetIndAttributeType(kRealNameAttrTypeNum),kDirectoryName,kDirNameLength,typeRString);
- if (err!=noErr)
- return err;
-
- // set name of directory to a unique name (we only have 1 slot, so we sort of hardcode this)
-
- err = SetRecNameAndType(&globalData->directoryCID,globalData->oceSetupDSRef,(RStringPtr)kDirectoryName,kDirectoryType);
- if (err!=noErr)
- return err;
-
- // add OCESetupDirectoryInfo
-
- err = AddDirectoryIdentity(&globalData->directoryCID,globalData->config.dirIdentity.userName,
- globalData->config.dirIdentity.password);
- if (err!=noErr)
- return err;
- strcpy(globalData->config.dirIdentity.oldPassword,globalData->config.dirIdentity.password);
-
- // add discriminator attribute (not needed according to setup document)
-
- err = AddAttribute(&globalData->directoryCID,globalData->oceSetupDSRef,
- OCEGetIndAttributeType(kDiscriminatorAttrTypeNum),&discriminator,sizeof(DirDiscriminator),typeBinary);
- if (err!=noErr)
- return err;
-
- // get reference to master OCE Setup Record
-
- err = GetSingleRecord(globalData->oceSetupDSRef,OCEGetIndRecordType(kSetupRecTypeNum),kOCESetupRecName,&ocesCID);
- if (err!=noErr)
- return err;
-
- // add our fake directory to the Directories attribute type
-
- MakePersonalRecordID(&dirRecordUnpacked,&globalData->directoryCID);
- err = OCEPackRecordID(&dirRecordUnpacked,&dirRecord,kPackedRecordIDMaxBytes);
- if (err!=noErr)
- return err;
- err = AddAttribute(&ocesCID,globalData->oceSetupDSRef,OCEGetIndAttributeType(kDirectoriesAttrTypeNum),
- &dirRecord,dirRecord.dataLength+sizeof(short),typeBinary);
- if (err!=noErr)
- return err;
-
-
- }
- else {
-
- // change OCESetupDirectoryInfo
-
- err = ChangeDirectoryIdentity(&globalData->directoryCID,globalData->config.dirIdentity.userName,
- globalData->config.dirIdentity.password,globalData->config.dirIdentity.oldPassword);
- strcpy(globalData->config.dirIdentity.oldPassword,globalData->config.dirIdentity.password);
- }
-
- }
-
- err = GetSingleRecord(globalData->oceSetupDSRef,OCEGetIndRecordType(kMSAMRecTypeNum),kMSAMRecordName,&msamCID);
- if (err!=noErr) {
-
- // make MSAM record
-
- err = AddRecord(globalData->oceSetupDSRef,kMSAMRecordName,OCEGetIndRecordType(kMSAMRecTypeNum),&msamCID);
- if (err!=noErr)
- return err;
-
- // add version
-
- version = kMSAMVersion;
- err = AddAttribute(&msamCID,globalData->oceSetupDSRef,kVersionAttribute,&version,sizeof(long),typeBinary);
- if (err!=noErr)
- return err;
-
- // add file id
-
- err = GetFileID(callBlockPtr,&fileID);
- if (err!=noErr)
- return err;
- err = AddAttribute(&msamCID,globalData->oceSetupDSRef,OCEGetIndAttributeType(kGatewayFileIDAttrTypeNum),
- &fileID,sizeof(long),typeBinary);
- if (err!=noErr)
- return err;
- }
- else {
-
- // make sure that the file ID attribute is still valid. If not, replace it, since the user may have upgraded
- // from an older version of the MSAM.
-
- err = GetFileID(callBlockPtr,&fileID);
- if (err!=noErr)
- return err;
- GetSingleValueAttribute(&msamCID,globalData->oceSetupDSRef,OCEGetIndAttributeType(kGatewayFileIDAttrTypeNum),
- &oldFileID,sizeof(long),&attrCID);
- if (err!=noErr)
- return err;
- if (oldFileID!=fileID) {
- err = ChangeSingleAttribute(&msamCID,globalData->oceSetupDSRef,OCEGetIndAttributeType(kGatewayFileIDAttrTypeNum),
- &fileID,sizeof(long),typeBinary);
- if (err!=noErr)
- return err;
- }
-
- }
-
- // add ParentMSAM attribute to mailservice record
-
- MakePersonalRecordID(&msRecordUnpacked,&msamCID);
- err = OCEPackRecordID(&msRecordUnpacked,&msRecord,kPackedRecordIDMaxBytes);
- if (err!=noErr)
- return err;
- err = AddAttribute(&globalData->mailCID,globalData->oceSetupDSRef,OCEGetIndAttributeType(kParentMSAMAttrTypeNum),
- &msRecord,msRecord.dataLength+sizeof(short),typeBinary);
- if (err!=noErr)
- return err;
-
- // add StdSlotInfo attribute to mailservice record
-
- err = AddAttribute(&globalData->mailCID,globalData->oceSetupDSRef,OCEGetIndAttributeType(kStdSlotInfoAttrTypeNum),
- &globalData->config.stdInfo,sizeof(MailStandardSlotInfoAttribute),typeBinary);
- if (err!=noErr)
- return err;
-
- // add SpecificSlotInfo to mailservice record
-
- err = AddAttribute(&globalData->mailCID,globalData->oceSetupDSRef,kSetupAttr,
- &globalData->config.specInfo,sizeof(SpecificSlotInfo),typeBinary);
- if (err!=noErr)
- return err;
-
- // call MailCreateMailSlot
-
- createMailSlot.mailboxRef = 0;
- createMailSlot.timeout = kTimeout;
- OCECopyCreationID(&msamCID,&createMailSlot.pmsamCID);
- createMailSlot.smca.smcaLength = sizeof(SMCA);
- createMailSlot.smca.result = 1; // call is running
- createMailSlot.smca.userBytes = 0;
- createMailSlot.ioCompletion = nil;
- OCECopyCreationID(&globalData->mailCID,&createMailSlot.smca.u.slotCID);
-
- err = MailCreateMailSlot((MSAMParam *)&createMailSlot);
- if (err!=noErr)
- return err;
-
- // wait for MailCreateMailSlot to complete
-
- while (createMailSlot.ioResult==1) {
- err = DoBusy(callBlockPtr);
- if (err!=noErr)
- return err;
- }
-
- // add new mailservices attribute to MSAM record since we were added successfully
-
- MakePersonalRecordID(&msRecordUnpacked,&globalData->mailCID);
- err = OCEPackRecordID(&msRecordUnpacked,&msRecord,kPackedRecordIDMaxBytes);
- if (err!=noErr)
- return err;
- err = AddAttribute(&msamCID,globalData->oceSetupDSRef,OCEGetIndAttributeType(kMailServiceAttrTypeNum),
- &msRecord,msRecord.dataLength+sizeof(short),typeBinary);
- if (err!=noErr)
- return err;
-
- return err;
- }
-
-
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
-
-
- // ChangeSingleAttribute
- //
- // changes the value of a single attribute to the new value passed in. this only works correctly if the attribute
- // type is single-valued
- //
- OSErr ChangeSingleAttribute(const CreationID *cid,short dsRef,AttributeType *attribType,void *data,unsigned long dataLength,AttributeTag tag)
- {
- OSErr err;
- CreationID oldCID;
- char *blank;
- Attribute oldAttribute,newAttribute;
- RecordID attrRecordID;
- DirParamBlock attrBlock;
-
- // set up aRecord parameter
-
- MakePersonalRecordID(&attrRecordID,cid);
-
- // set up currentAttr parameter
-
- err = GetSingleValueAttribute(cid,dsRef,attribType,nil,0L,&oldCID);
- if (err!=noErr)
- return err; // no previous record
- for (blank=(char*)&oldAttribute;(blank-(char*)&oldAttribute)<sizeof(Attribute);blank++)
- *blank=0;
- OCECopyCreationID(&oldCID,&oldAttribute.cid);
-
- // set up newAttr parameter
-
- for (blank=(char*)&newAttribute;(blank-(char*)&newAttribute)<sizeof(Attribute);blank++)
- *blank=0;
- OCECopyRString((const RString *)attribType, (RString *)&newAttribute.attributeType,kAttributeTypeMaxBytes);
- newAttribute.value.tag = tag;
- newAttribute.value.dataLength = dataLength;
- newAttribute.value.bytes = (Ptr)data;
-
- attrBlock.changeAttributeValuePB.serverHint.aNet = 0;
- attrBlock.changeAttributeValuePB.serverHint.aNode = 0;
- attrBlock.changeAttributeValuePB.serverHint.aSocket = 0;
- attrBlock.changeAttributeValuePB.dsRefNum = dsRef;
- attrBlock.changeAttributeValuePB.identity = kIdentity;
- attrBlock.changeAttributeValuePB.aRecord = &attrRecordID;
- attrBlock.changeAttributeValuePB.currentAttr = &oldAttribute;
- attrBlock.changeAttributeValuePB.newAttr = &newAttribute;
- err = DirChangeAttributeValue(&attrBlock,false);
- return err;
- }
-
-
- // DeleteAttributeType
- //
- // deletes the attribute type passed in and all associated
- // values to that type
- //
- OSErr DeleteAttributeType(const CreationID *cid,short dsRef,AttributeType *attribType)
- {
- OSErr err;
- RecordID attrRecordID;
- char *blank;
- DirParamBlock dirBlock;
-
- MakePersonalRecordID(&attrRecordID,cid);
-
- for (blank=(char*)&dirBlock;(blank-(char*)&dirBlock)<sizeof(DirParamBlock);blank++)
- *blank=0;
-
- dirBlock.deleteAttributeTypePB.serverHint.aNet = 0;
- dirBlock.deleteAttributeTypePB.serverHint.aNode = 0;
- dirBlock.deleteAttributeTypePB.serverHint.aSocket = 0;
- dirBlock.deleteAttributeTypePB.dsRefNum = dsRef;
- dirBlock.deleteAttributeTypePB.identity = kIdentity;
- dirBlock.deleteAttributeTypePB.aRecord = &attrRecordID;
- dirBlock.deleteAttributeTypePB.attrType = attribType;
- err = DirDeleteAttributeValue(&dirBlock,false);
- return err;
- }
-
-
- // GetSingleValueAttribute
- //
- // this routine returns a single attribute value from a record. it's used to get information out
- // of the slot setup information
- //
- OSErr GetSingleValueAttribute(const CreationID *cid,short dsRef,AttributeType *attribType,void *attrBuffer,Size attrBufferSize,CreationID *retCID)
- {
- DirParamBlock dirBlock;
- Ptr buff;
- OSErr err;
- RecordIDPtr recordList[1];
- AttributeTypePtr attrList[1];
- RecordID recordID;
- char *blank;
- AttributeCopyInfo callbackInfo;
-
- callbackInfo.buffer = attrBuffer;
- callbackInfo.bufferSize = attrBufferSize;
- callbackInfo.creationID = retCID;
- callbackInfo.gotOne = false;
-
- MakePersonalRecordID(&recordID,cid);
-
- recordList[0] = (RecordIDPtr)&recordID;
- attrList[0] = attribType;
- buff = NewPtr(kAttrBufferSize);
- if (MemError()!=noErr)
- return MemError();
-
- for (blank=(char*)&dirBlock;(blank-(char*)&dirBlock)<sizeof(DirParamBlock);blank++)
- *blank=0;
-
- dirBlock.header.ioCompletion = nil;
- dirBlock.header.clientData = (long)&callbackInfo;
- dirBlock.lookupGetPB.serverHint.aNet = 0;
- dirBlock.lookupGetPB.serverHint.aNode = 0;
- dirBlock.lookupGetPB.serverHint.aSocket = 0;
- dirBlock.lookupGetPB.dsRefNum = dsRef;
- dirBlock.lookupGetPB.identity = kIdentity;
- dirBlock.lookupGetPB.aRecordList = recordList;
- dirBlock.lookupGetPB.attrTypeList = attrList;
- dirBlock.lookupGetPB.recordIDCount = 1;
- dirBlock.lookupGetPB.attrTypeCount = 1;
- dirBlock.lookupGetPB.includeStartingPoint = false;
- dirBlock.lookupGetPB.getBuffer = buff;
- dirBlock.lookupGetPB.getBufferSize = kAttrBufferSize;
- dirBlock.lookupGetPB.startingRecordIndex = 1;
- dirBlock.lookupGetPB.startingAttrTypeIndex = 1;
- dirBlock.lookupParsePB.eachRecordID = RecordIDCallback;
- dirBlock.lookupParsePB.eachAttrType = nil;
- dirBlock.lookupParsePB.eachAttrValue = SingleAttrValueCallback;
- OCESetCreationIDtoNull(&dirBlock.lookupGetPB.startingAttribute.cid);
-
- err = DirLookupGet(&dirBlock,false);
- if (err==noErr || err==kOCEMoreData)
- err = DirLookupParse(&dirBlock,false);
-
- if ((err==noErr) && !callbackInfo.gotOne)
- err = kNoRecords;
-
- DisposPtr(buff);
- return err;
- }
-
-
- pascal Boolean RecordIDCallback(long clientData, const RecordID *recordID)
- {
- #pragma unused (clientData,recordID)
- return false;
- }
-
-
- pascal Boolean SingleAttrValueCallback(long clientData, const Attribute *attribute)
- {
- AttributeCopyInfoPtr callbackInfo;
- Size moveSize;
-
- callbackInfo = (AttributeCopyInfoPtr) clientData;
-
- if (callbackInfo->bufferSize>0) {
- moveSize = attribute->value.dataLength;
- if (moveSize>callbackInfo->bufferSize)
- moveSize = callbackInfo->bufferSize;
- BlockMove(attribute->value.bytes,callbackInfo->buffer,moveSize);
- }
-
- OCECopyCreationID(&attribute->cid,callbackInfo->creationID);
- callbackInfo->gotOne = true;
-
- return false;
- }
-
-
- // GetSingleRecord
- //
- // returns the RecordID for a record of a given type, if it matches the name you were
- // looking for which is passed in
- //
- OSErr GetSingleRecord(short dsRef,RStringPtr recordType,RStringPtr recordName,CreationID *returnedCID)
- {
- DirParamBlock dirBlock;
- Ptr buff;
- char *blank;
- RStringPtr typesList[1];
- OSErr err;
- RecordCopyInfo recCopyInfo;
-
- buff = NewPtr(kRecordBufferSize);
- if (MemError()!=noErr)
- return MemError();
-
- for (blank=(char*)&dirBlock;(blank-(char*)&dirBlock)<sizeof(DirParamBlock);blank++)
- *blank=0;
-
- typesList[0] = recordType;
-
- recCopyInfo.gotOne = false;
- recCopyInfo.creationID = returnedCID;
- recCopyInfo.recordName = recordName;
-
- dirBlock.enumerateGetPB.serverHint.aNet = 0;
- dirBlock.enumerateGetPB.serverHint.aNode = 0;
- dirBlock.enumerateGetPB.serverHint.aSocket = 0;
- dirBlock.enumerateGetPB.dsRefNum = dsRef;
- dirBlock.enumerateGetPB.identity = kIdentity;
- dirBlock.enumerateGetPB.clientData = (long)&recCopyInfo;
- dirBlock.enumerateGetPB.aRLI = nil;
- dirBlock.enumerateGetPB.startingPoint = nil;
- dirBlock.enumerateGetPB.sortBy = kSortByName;
- dirBlock.enumerateGetPB.sortDirection = kSortForwards;
- dirBlock.enumerateGetPB.typesList = typesList;
- dirBlock.enumerateGetPB.typeCount = 1;
- dirBlock.enumerateGetPB.enumFlags = kEnumDistinguishedNameMask;
- dirBlock.enumerateGetPB.includeStartingPoint = false;
- dirBlock.enumerateGetPB.getBuffer = buff;
- dirBlock.enumerateGetPB.getBufferSize = kRecordBufferSize;
- dirBlock.enumerateParsePB.eachEnumSpec = GatewayDirEnumCallback;
-
- err = DirEnumerateGet(&dirBlock,false);
- if (err==noErr || err==kOCEMoreData)
- err = DirEnumerateParse(&dirBlock,false);
-
- DisposPtr(buff);
-
- if ((err==noErr) && !recCopyInfo.gotOne)
- err = kNoRecords;
-
- return err;
- }
-
-
- pascal Boolean GatewayDirEnumCallback(long clientData, const DirEnumSpec *enumSpec)
- {
- RecordCopyInfo *recCopyInfo;
-
- recCopyInfo = (RecordCopyInfo *)clientData;
-
- if (!recCopyInfo->gotOne && enumSpec->enumFlag & kEnumDistinguishedNameMask &&
- OCEEqualRString(recCopyInfo->recordName,enumSpec->u.recordIdentifier.recordName,kOCERecordOrDNodeName)) {
-
- OCECopyCreationID(&enumSpec->u.recordIdentifier.cid,recCopyInfo->creationID);
- recCopyInfo->gotOne = true;
- return true;
-
- }
- return false;
- }
-
-
- // AddAttribute
- //
- // add an attribute value to a record
- //
- OSErr AddAttribute(const CreationID *cid,short dsRef,AttributeType *attribType,void *data,unsigned long dataLength,AttributeTag tag)
- {
- DirParamBlock attrBlock;
- RecordID recordID;
- Attribute attribute;
- OSErr err;
- char *blank;
-
- MakePersonalRecordID(&recordID,cid);
-
- attrBlock.addAttributeValuePB.serverHint.aNet = 0;
- attrBlock.addAttributeValuePB.serverHint.aNode = 0;
- attrBlock.addAttributeValuePB.serverHint.aSocket = 0;
- attrBlock.addAttributeValuePB.dsRefNum = dsRef;
- attrBlock.addAttributeValuePB.identity = kIdentity;
- attrBlock.addAttributeValuePB.aRecord = &recordID;
- attrBlock.addAttributeValuePB.attr = &attribute;
-
- for (blank=(char*)&attribute;(blank-(char*)&attribute)<sizeof(Attribute);blank++)
- *blank=0;
- OCECopyRString((const RString *)attribType, (RString *)&attribute.attributeType,kAttributeTypeMaxBytes);
- attribute.value.tag = tag;
- attribute.value.dataLength = dataLength;
- attribute.value.bytes = (Ptr)data;
- err = DirAddAttributeValue(&attrBlock,false);
-
- return err;
- }
-
-
- // SetRecNameAndType
- //
- // sets the name and type of the record pointed to by the CID passed in
- //
- OSErr SetRecNameAndType(const CreationID *cid,short dsRef,RStringPtr newName,RStringPtr newType)
- {
- DirSetNameAndTypePB dirBlock;
- RecordID recordID;
- OSErr err;
-
- MakePersonalRecordID(&recordID,cid);
-
- dirBlock.serverHint.aNet = 0;
- dirBlock.serverHint.aNode = 0;
- dirBlock.serverHint.aSocket = 0;
- dirBlock.dsRefNum = dsRef;
- dirBlock.identity = kIdentity;
- dirBlock.aRecord = &recordID;
- dirBlock.allowDuplicate = false; // don't allow duplicate name/type
- dirBlock.newName = newName;
- dirBlock.newType = newType;
- err = DirSetNameAndType((DirParamBlockPtr)&dirBlock,false);
-
- return err;
- }
-
-
- // AddRecord
- //
- // adds a record into a personal directory and returns its CID
- //
- OSErr AddRecord(short dsRefNum,RStringPtr recordName,RStringPtr recordType,CreationID *newCID)
- {
- DirAddRecordPB addRecordPB;
- OSErr err;
- RecordID recordID;
-
- addRecordPB.serverHint.aNet = 0;
- addRecordPB.serverHint.aNode = 0;
- addRecordPB.serverHint.aSocket = 0;
- addRecordPB.dsRefNum = dsRefNum;
- addRecordPB.identity = kIdentity;
- addRecordPB.allowDuplicate = false;
- addRecordPB.aRecord = &recordID;
- recordID.local.recordName = recordName;
- recordID.local.recordType = recordType;
- recordID.rli = nil;
- OCESetCreationIDtoNull(&recordID.local.cid);
- err = DirAddRecord((DirParamBlock*)&addRecordPB,false);
- if (err==noErr)
- OCECopyCreationID(&recordID.local.cid,newCID);
-
- return err;
- }
-
-
- // AddDirectoryIdentity
- //
- // add a name and password identity to a directory record
- //
- OSErr AddDirectoryIdentity(const CreationID *cid,char *userName,char *password)
- {
- OCESetupAddDirectoryInfoPB authBlock;
- OSErr err;
- RString rsUserName,rsPassword;
- DirDiscriminator discriminator = {kDirectoryOSType, 0};
- DNodeNum dNodeNumber = 0;
- PackedRLI pRLI;
- RecordID userRID;
-
- OCECToRString(userName, smRoman, &rsUserName, kRStringMaxChars);
- OCECToRString(password, smRoman, &rsPassword, kRStringMaxChars);
- OCEPackRLIParts(kDirectoryName, &discriminator, dNodeNumber, nil, 0, &pRLI, kPackedRecordIDMaxBytes);
- userRID.rli = &pRLI;
- userRID.local.recordName = &rsUserName;
- userRID.local.recordType = OCEGetIndRecordType(kUserRecTypeNum);
- OCECopyCreationID(cid,&authBlock.directoryRecordCID);
- authBlock.recordID = &userRID;
- authBlock.password = &rsPassword;
- err = OCESetupAddDirectoryInfo((AuthParamBlockPtr)&authBlock,false);
-
- return err;
- }
-
-
- // ChangeDirectoryIdentity
- //
- // change an existing directory identity
- //
- OSErr ChangeDirectoryIdentity(const CreationID *cid,char *userName,char *password,char *oldPassword)
- {
- OCESetupChangeDirectoryInfoPB authBlock;
- OSErr err;
- RString rsUserName,rsPassword,rsOldPassword;
- DirDiscriminator discriminator = {kDirectoryOSType, 0};
- DNodeNum dNodeNumber = 0;
- PackedRLI pRLI;
- RecordID userRID;
-
- OCECToRString(userName, smRoman, &rsUserName, kRStringMaxChars);
- OCECToRString(password, smRoman, &rsPassword, kRStringMaxChars);
- OCECToRString(oldPassword, smRoman, &rsOldPassword, kRStringMaxChars);
- OCEPackRLIParts(kDirectoryName, &discriminator, dNodeNumber, nil, 0, &pRLI, kPackedRecordIDMaxBytes);
- userRID.rli = &pRLI;
- userRID.local.recordName = &rsUserName;
- userRID.local.recordType = OCEGetIndRecordType(kUserRecTypeNum);
- OCECopyCreationID(cid,&authBlock.directoryRecordCID);
- authBlock.recordID = &userRID;
- authBlock.password = &rsOldPassword;
- authBlock.newPassword = &rsPassword;
- err = OCESetupChangeDirectoryInfo((AuthParamBlockPtr)&authBlock,false);
-
- return err;
- }
-
-
- // MakePersonalRecordID
- //
- // this convenience function fills in a RecordID given a creation ID, since a fully specified
- // record ID for a personal directory contains only a creation ID
- //
- void MakePersonalRecordID(RecordID *recordID,const CreationID *creationID)
- {
- recordID->rli = nil;
- OCECopyCreationID(creationID,&recordID->local.cid);
- recordID->local.recordName = nil;
- recordID->local.recordType = nil;
- }
-
-
- // GetCreationIDFromDSSpec
- //
- // pulls the CreationID out of a PackedDSSpec
- //
- void GetCreationIDFromDSSpec(const PackedDSSpec *dsSpec,CreationID *cid)
- {
- DSSpec unpackedDSSpec;
- RecordID recordID;
-
- OCEUnpackDSSpec(dsSpec,&unpackedDSSpec,&recordID);
- OCECopyCreationID(&recordID.local.cid,cid);
- }
-
-
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
-
- OSErr SetUserPassword(char *passwordStorage)
- {
- short saveResFile,myResFile;
- Handle codeHndl;
-
- // set our resource file to the current resource file
-
- saveResFile = CurResFile();
- codeHndl = RecoverHandle((Ptr)MailServiceCode);
- if (!codeHndl)
- return kInternalError;
- myResFile = HomeResFile(codeHndl);
- if (myResFile==0 || myResFile==1 || myResFile==-1)
- return kInternalError;
- UseResFile(myResFile);
-
- // let the user change the password (given the old one)
-
- ChangePassword(passwordStorage);
-
- // restore the old resource file
- UseResFile(saveResFile);
-
- return noErr;
- }
-
-
- void ChangePassword(char *pwStorage)
- {
- char oldPassword[64],newPassword[64];
-
- if (!GetPasswordDialog(oldPassword,newPassword,pwStorage[0]!=0))
- return; // user cancelled
-
- if (strcmp(oldPassword,pwStorage)!=0) {
- StopAlert(kIncorrectPWAlert,nil);
- return;
- }
-
- strcpy(pwStorage,newPassword);
- }
-
-
- Boolean GetPasswordDialog(char *oldPassword,char *password,Boolean hasPassword)
- {
- short item;
- DialogPtr theDialog;
- PasswordDialogData theData;
-
- oldPassword[0] = 0;
- password[0] = 0;
- theData.oldPassword = oldPassword;
- theData.password = password;
-
- if (hasPassword)
- theDialog = GetNewDialog(kPasswordDialog,nil,(WindowPtr)-1L);
- else
- theDialog = GetNewDialog(kNoPrevPassDialog,nil,(WindowPtr)-1L);
-
- SetWRefCon(theDialog,(long)&theData);
- do
- ModalDialog(PasswordFilter,&item);
- while (item!=ok&&item!=cancel);
- DisposeDialog(theDialog);
-
- if (!hasPassword) {
- strcpy(password,oldPassword);
- oldPassword[0] = 0;
- }
-
- return (item==ok);
- }
-
-
- pascal Boolean PasswordFilter(DialogPtr theDialog,EventRecord *theEvent,short *itemHit)
- {
- DialogPeek dPeek;
- char theChar;
- short selStart,selEnd;
- PasswordDialogData *theData;
- char *theStr;
- short iType;
- Handle iHndl;
- Rect iRect;
-
- dPeek = (DialogPeek) theDialog;
- if (!dPeek)
- return false;
-
- theData = (PasswordDialogData *)GetWRefCon(theDialog);
- if ((dPeek->editField+1)==kOldPasswordItem)
- theStr = theData->oldPassword;
- else if ((dPeek->editField+1)==kNewPasswordItem)
- theStr = theData->password;
- else
- theStr = nil;
-
- switch (theEvent->what) {
- case keyDown:
- case autoKey:
- theChar = theEvent->message & charCodeMask;
- selStart = (**(dPeek->textH)).selStart;
- selEnd = (**(dPeek->textH)).selEnd;
- if (selEnd>strlen(theStr))
- selEnd = strlen(theStr);
- switch (theChar) {
- case 0x08: /* backspace */
- if (selStart == selEnd) {
- if (selStart > 0)
- BlockMove((Ptr)theStr + selStart,(Ptr)theStr + selStart-1,strlen(theStr)-selStart+1);
- }
- else
- BlockMove((Ptr)theStr + selEnd,(Ptr)theStr + selStart,strlen(theStr)-selEnd+1);
- break;
- case 0x0d: /* CR */
- case 0x03: /* enter */
- *itemHit = ok;
- GetDItem(theDialog,ok,&iType,&iHndl,&iRect);
- HiliteControl((ControlHandle)iHndl,inButton);
- return true;
- break;
- case 0x09: /* tab */
- case 0x1c: /* left */
- case 0x1d: /* right */
- case 0x1e: /* up */
- case 0x1f: /* down */
- return false;
- break;
- case 0x1b:
- *itemHit = cancel;
- GetDItem(theDialog,cancel,&iType,&iHndl,&iRect);
- HiliteControl((ControlHandle)iHndl,inButton);
- return true;
- break;
- case '.':
- if ((theEvent->modifiers & cmdKey) != 0) {
- *itemHit = cancel;
- GetDItem(theDialog,cancel,&iType,&iHndl,&iRect);
- HiliteControl((ControlHandle)iHndl,inButton);
- return true;
- }
- default:
- BlockMove((Ptr)theStr+selEnd,(Ptr)theStr+selStart+1,strlen(theStr)-selEnd+1);
- *(theStr+selStart) = theChar;
- theEvent->message = 0xffffff00 + '•';
- return false;
- break;
- }
- break;
- }
-
- return false;
- }
-
-
- //---------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------------
-
- void DoError(OSErr err)
- {
- #pragma unused (err)
- #ifdef kDEBUG
- DebugStr("\perror");
- #else
- SysBeep(1);
- #endif
- }